<template>
	<div class="discount-hb">
		<!--<discountnav :msg="1"></discountnav>-->
		<div id="kong">
			<img class="kong-img" src="../../img-shopping/yhq@2x.png"/>
			<p class="kong-p">这里空空如也呢~</p>
		</div>
		<ul class="discount-list" v-if="hblist.length>0">
			<li class="discount-item" v-for="item in hblist">
				<div class="discount-xinxi">
					<h3 v-text="item.coupon_name"></h3>
					<span v-text="item.min_amount>0?item.min_amount:'无门槛'"></span>
					<p>使用期限 <span v-text="item.start_time"></span>-<span v-text="item.end_time"></span></p>
				</div>
				<div class="discount-jine">
					<h3 v-html="'<span>￥</span>'+item.coupon_value"></h3>
					<span v-text="(item.type==1&&item.store_id==0)?'平台优惠券':'优惠券'"></span>
				</div>
			</li>
		</ul>
	</div>
</template>

<script>
//	import discountnav from '@/components/user-group/discountnav'
	export default{
		name:'discounthb',
//		components:{discountnav},
		data () {
			return{
				user:0,
				type:'packe',
				hblist:[],
				page:1,
				pagenum:0,
				scrollstatu:true
			}
		},
		created:function(){
			this.user=localStorage.getItem("nt_user");
		},
		methods:{
			ajaxhb:function(){
				var self=this;
				$.ajax({
					type:"get",
					url:furl+"index.php?app=ajax_coupon&act=index",
					data:{'token':self.user,'type':self.type,'page':self.page},
					dataType:'json',
					success:function(res){
						if(res.done){
							for(var key in res.retval.coupons){
								res.retval.coupons[key].start_time=new Date(Number(res.retval.coupons[key].start_time)*1000).Format("yyyy.MM.dd");
								res.retval.coupons[key].end_time=new Date(Number(res.retval.coupons[key].end_time)*1000).Format('yyyy.MM.dd');
								self.hblist.push(res.retval.coupons[key]);
							}
							self.pagenum=res.retval.page.page_count;
							if(self.hblist.length<=0){
								console.log("暂时没有数据");
							}
						}else{
							if(self.hblist.length<=0){
								console.log("请求数据失败");
							}
						}
						self.panduanyh = res.retval.page.item_count
						if(self.panduanyh!=0){
							$("#kong").css("display","none")
						}
					}
				});
				
			},
			scrollajax:function(){
				if(this.scrollstatu){
					if(this.page+1<=this.pagenum){
						var dSH=$(document).scrollTop()
						var dH=$(document).height()
						var wH=$(window).height()
						if((dSH+wH)/dH>0.8){
							this.scrollstatu=false;
							this.page=this.page+1;
							console.log(this.page);
							this.ajaxhb();
						}
					}
					
				}
			}
		},
		mounted:function(){
			this.ajaxhb();
			var self=this;
			window.addEventListener('scroll',self.scrollajax);
		},
		destroyed:function () {
		    this.scrollstatu = false;
		}
	}
</script>

<style>
	.discount-hb{font-size:0;}
	.discount-list{padding-left:0.27rem;padding-right:0.27rem;padding-top: 0.38rem;}
	.discount-item{background-image:url(../../img-discount/hbbg.png);background-repeat:no-repeat;background-size:100%;position:relative;margin-bottom: 0.16rem;}
	.discount-sy{position:absolute;top:-0.11rem;right:-0.12rem;width:1.1rem;height:0.84rem;}
	.discount-xinxi{display:inline-block;width:4.5rem;height:2.25rem;box-sizing: border-box;padding: 0.4rem 0 0 0.4rem;}
	.discount-xinxi>h3{font-size:0.32rem;color:#2b2b2b;line-height: 0.3rem;margin-bottom: 0.24rem;}
	.discount-xinxi>span{display:inline-block;font-size:0.24rem;color:#fb9722;line-height: 0.23rem;margin-bottom: 0.39rem;font-weight:600;}
	.discount-xinxi>p{font-size:0.22rem;color:#999;line-height: 0.22rem;}
	.discount-jine{display: inline-block;width:2.3rem;float:right;margin-right: 0.08rem;text-align: center;}
	.discount-jine>h3{font-size:0.5rem;color:#fb9722;line-height: 0.6rem;margin-bottom: 0.1rem;margin-top: 0.54rem;font-weight:500;margin-right: 0.2rem;}
	.discount-jine>h3>span{font-size:0.4rem;}
	.discount-jine>span{font-size:0.24rem;color:#fb9722;line-height: 0.24rem;}
	.diacount-shixiao h3,.diacount-shixiao span,.diacount-shixiao p{color:#999 !important;}
	#kong{
		text-align: center;
		margin: 0 auto;
		margin-top: 1.59rem;
	}
	#kong img{
		width: 3.6rem;
		height: 3.2rem;
	}
	#kong .kong-p{
		font-size: 0.32rem;
		color: #999999;
		margin-top: 0.84rem;
	}
	#kong .kong-b{
		width: 1.8rem;
		height: 0.7rem;
		border:1px solid #fb9722;
		margin-left:2.85rem;
		margin-top: 0.44rem;
		border-radius: 0.35rem;
	}
	#kong .kong-btn{
		font-size: 0.33rem;
		color: #fb9722;
		line-height: 0.7rem;
	}
</style>